/*
 * Subscriber.java
 * 
 * Version Information
 * Date Mar 20, 2006
 *
 * Copyright (c) AmSoft Systems, 2006
 */
package net.amsoft.iservice.ilink.hibernate;

import java.util.HashSet;
import java.util.Set;

import org.apache.log4j.Logger;

import net.amsoft.iservice.util.exception.IServiceException;

/**
 * @author jyoti
 * 
 */
public class Subscriber extends ILinkBaseClass {
	private static final Logger oLogger = Logger.getLogger(Subscriber.class);

	private IBroker oIBroker;

	private Set<Synonym> oSynonyms = new HashSet<Synonym>();

	public Subscriber() {
	}

	public IBroker getBroker() {
		return this.oIBroker;
	}

	public void setBroker(IBroker oBroker) {
		this.oIBroker = oBroker;
	}

	public Set getSynonyms() {
		return this.oSynonyms;
	}

	public void setSynonyms(Set<Synonym> synonyms) {
		this.oSynonyms = synonyms;
	}

	public void addSynonym(Synonym oSynonym) throws IServiceException {
		oSynonym.setSubscriber(this);
		this.oSynonyms.add(oSynonym);
		try {
			oSynonym.insert();
		} catch (IServiceException e) {
			oLogger.warn("addSynonym() : Exception : " + e.getMessage());
			throw e;
		}
	}

	public void removeSynonym(Synonym synonym) {
		synonym.remove();
	}

	public void debug(String prefix) {
		this.update();
		oLogger.debug(prefix + " : Subscriber (" + id + ", " + oIBroker.getId()
				+ ", " + creationTime + ", " + modificationTime + ", "
				+ oSynonyms.size() + ", " + state + ")");
	}
}